package com.haha.helloworld.jump;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.haha.helloworld.R;

public class BActivity extends AppCompatActivity {
    private TextView tv_title;
    private Button btn_finish;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bactivity);
        tv_title=(TextView) findViewById(R.id.tv_title);
        //获取在A Activity传过来的Bundle
        Bundle extras = getIntent().getExtras();
        String name = (String)extras.get("name");
        int number =(int) extras.get("number");
        //给控件设置值
        tv_title.setText("A传递过来的："+"name==>"+name+"number==>"+number);



        btn_finish= (Button) findViewById(R.id.btn_finish);
        btn_finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("title","B的返回值：我回来了");
                intent.putExtras(bundle);
                setResult(AActivity.RESULT_OK,intent);
                //结束当前页面
                finish();
            }
        });
    }
}